import requests

cookies = {
    'JSESSIONID': 'B0E085CA0E04A0D68518218101A3DDD8',
    'tempTokenKey': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjgyLCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzI1MzI2MTkyLCJleHAiOjE3MjUzNTQ5OTJ9.-JX7sbNjbfO4-9Lb4XAUi3U3QWyxmgeiy2KdZAStsUGmhSJLBW6i9Y4g0NB1kn2d7ULCYmy5U3_2On4DXVPqDA',
    'userInfoKey': '{^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:82^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}',
    'pwdState': 'true',
    'inspurRoleKey': 'ROLE_AREA',
    'windowId': '0B7CA12E92004E0ABCA9EB88F0A792E4',
    'wyhtml': '/tyspzy/_191b6031d28100d_1725335543080',
    'James_cookie_sYQDUGqqzHtheme': 'custom',
    'wyhijack': '/zhslzy/static/js/threejs/threejs.js_1725344950546',
    'webfinal.session.errorCount': '0',
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    # 'Accept-Encoding': 'gzip, deflate',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'X-Requested-With': 'XMLHttpRequest',
    'Origin': 'http://59.215.206.188',
    'Connection': 'keep-alive',
    'Referer': 'http://59.215.206.188/sxgl/mng/a520000000000/confirm/fxkorgcode/index?v=1725347963061',
    # 'Cookie': 'JSESSIONID=B0E085CA0E04A0D68518218101A3DDD8; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjgyLCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzI1MzI2MTkyLCJleHAiOjE3MjUzNTQ5OTJ9.-JX7sbNjbfO4-9Lb4XAUi3U3QWyxmgeiy2KdZAStsUGmhSJLBW6i9Y4g0NB1kn2d7ULCYmy5U3_2On4DXVPqDA; userInfoKey={^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:82^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4; wyhtml=/tyspzy/_191b6031d28100d_1725335543080; James_cookie_sYQDUGqqzHtheme=custom; wyhijack=/zhslzy/static/js/threejs/threejs.js_1725344950546; webfinal.session.errorCount=0',
    'Priority': 'u=0',
}

data = '_search=true&nd=1725347982619&rows=1000&page=1&sidx=&sord=&regionCode=520300,520302,520303,520321,520322,520323,520324,520325,520326,520327,520328,520329,520330,520381,520382,520383&orgCode='


response = requests.post(
    'http://59.215.206.188/sxgl/mng/a520000000000/confirm/fxkorgcode/query',
    cookies=cookies,
    headers=headers,
    data=data,
).json()
list=[]
for i in response['rows']:
    # try:
    #     if f'5203' in i['cell']['REGION_CODE']:
    REGION_NAME	 = i['cell']['REGION_NAME']
    ORG_NAME=i['cell']['ORG_NAME']

    EDITOR	=i['cell']['EDITOR']
    CREATE_TIME	=i['cell']['CREATE_TIME']
    list.append([REGION_NAME	,ORG_NAME,EDITOR,CREATE_TIME])
    print(REGION_NAME,ORG_NAME,EDITOR,CREATE_TIME)
    # except:pass
import pandas as pd

# 创建 DataFrame，并设置列名
df = pd.DataFrame(list, columns=['区划', '部门', '确认人', '确认时间'])
from datetime import datetime
# 获取今天的日期
today_date = str(datetime.today().date())
# 写入 Excel 文件
excel_file_path = f'{today_date}国办事项推送情况.xlsx'
df.to_excel(excel_file_path, index=False)


print(f"Data written to {today_date+'国办事项推送情况'}")